<template>
  <div class="my-popover-btn my-disable-btn" @click="handleClick" v-if="content && disabled">
    <!--          显示的内容-->
    <div>
      <input class="my-show-span my-span-input" type="text" disabled :value="formattedContent" />
    </div>
    <!--          后缀-->
    <slot name="suffix">
      <i class="my-suffix el-icon-s-grid"></i>
    </slot>
  </div>
  <div class="my-popover-btn" @click="handleClick" v-else>
    <!--          显示的内容-->
    <div>
      <span class="my-placeholder" v-if="placeholder && !content">{{ placeholder }}</span>
      <span class="my-show-span" v-if="content">{{ formattedContent }}</span>
      <span class="my-show-span" v-if="content && disabled">{{ formattedContent }}</span>
    </div>
    <!--          后缀-->
    <slot name="suffix">
      <i class="my-suffix el-icon-s-grid"></i>
    </slot>
  </div>
</template>

<script>
export default {
  name: 'MyPopoverBtn',
  props: {
    placeholder: {
      required: false
    },
    content: {
      required: false
    },
    disabled: {
      required: false,
      default: false
    }
  },
  computed: {
    formattedContent() {
      if (this.content instanceof Array) {
        return this.content.join(' \\ ')
      }
      return this.content
    }
  },
  methods: {
    // 点击框框
    handleClick() {
      if (this.disabled) {
        return
      }
      this.$emit('click')
    }
  }
}
</script>

<style scoped lang="scss">
$lightColor: #C0C4CC;
$normalBorderColor: #DCDFE6;
$hoverBorderColor: #C0C4CC;
$fontColor: #606266;

.my-popover-btn {
  position: relative;
  width: 205px;
  height: 32px;
  line-height: 32px;
  padding: 0 30px 0 15px;
  border: 1px solid $normalBorderColor;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;

  &:hover {
    border-color: $hoverBorderColor;
  }

  .my-placeholder {
    color: $lightColor;
  }

  .my-show-span {
    color: $fontColor;
  }

  .my-span-input {
    background-color: #F5F7FA;
    border: none;
    color: #C0C4CC;
    cursor: not-allowed;
  }

  .my-suffix {
    display: block;
    position: absolute;
    top: 50%;
    right: 8px;
    width: 14px;
    height: 14px;
    text-align: center;
    line-height: 14px;
    transform: translateY(-50%);
    color: $lightColor;
  }
}

.my-disable-btn {
  background-color: #F5F7FA;
  cursor: not-allowed;

  &:hover {
    border-color: $normalBorderColor;
  }
}
</style>
